#pragma once
#include<string>
#include<iostream>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
using namespace std;

#define Mode 0666

//创建命名管道
class Fifo
{
public:
    Fifo(const string&path)
        :_path(path)
    {
        umask(0);
        int ret=mkfifo(_path.c_str(),Mode);
        if(ret==0)
        {
            cout<<"Pipeline created successfully"<<endl;
        }
        else
        {
            perror("mkfifo");
        }
    }

    //在析构的时候删除创建的管道文件
    ~Fifo()
    {
        int ret=unlink(_path.c_str());
        if(ret==0)
        {
            cout<<"Deleted pipeline successfully"<<endl;
        }
        else
        {
            perror("nulink");
        }
    }
private:
    string _path;
};